Public Class DTSPackager
    Inherits System.Windows.Forms.Form

    Private __oSQL As Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase
    Private __sMessage As String
    Private __bConnTested As Boolean = False

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents txtUserName As System.Windows.Forms.TextBox
    Friend WithEvents lblUserName As System.Windows.Forms.Label
    Friend WithEvents txtSrvName As System.Windows.Forms.TextBox
    Friend WithEvents lblSrvName As System.Windows.Forms.Label
    Friend WithEvents btnGetPkgList As System.Windows.Forms.Button
    Friend WithEvents lblPassword As System.Windows.Forms.Label
    Friend WithEvents lblFilePath As System.Windows.Forms.Label
    Friend WithEvents txtOutFilePath As System.Windows.Forms.TextBox
    Friend WithEvents btnPkgSelected As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents chklbPkgList As System.Windows.Forms.CheckedListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cbCrManifest As System.Windows.Forms.CheckBox
    Friend WithEvents lbMessage As System.Windows.Forms.ListBox
    Friend WithEvents txtManifestFileName As System.Windows.Forms.TextBox
    Friend WithEvents chkSelectAllOnGet As System.Windows.Forms.CheckBox
    Friend WithEvents chkTrusted As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(DTSPackager))
        Me.lblPassword = New System.Windows.Forms.Label
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.txtUserName = New System.Windows.Forms.TextBox
        Me.lblUserName = New System.Windows.Forms.Label
        Me.txtSrvName = New System.Windows.Forms.TextBox
        Me.lblSrvName = New System.Windows.Forms.Label
        Me.btnGetPkgList = New System.Windows.Forms.Button
        Me.chklbPkgList = New System.Windows.Forms.CheckedListBox
        Me.lblFilePath = New System.Windows.Forms.Label
        Me.txtOutFilePath = New System.Windows.Forms.TextBox
        Me.btnPkgSelected = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.txtManifestFileName = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.cbCrManifest = New System.Windows.Forms.CheckBox
        Me.lbMessage = New System.Windows.Forms.ListBox
        Me.chkTrusted = New System.Windows.Forms.CheckBox
        Me.chkSelectAllOnGet = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'lblPassword
        '
        Me.lblPassword.Location = New System.Drawing.Point(4, 56)
        Me.lblPassword.Name = "lblPassword"
        Me.lblPassword.Size = New System.Drawing.Size(84, 16)
        Me.lblPassword.TabIndex = 21
        Me.lblPassword.Text = "Password:"
        '
        'txtPassword
        '
        Me.txtPassword.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtPassword.Location = New System.Drawing.Point(92, 52)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(154, 20)
        Me.txtPassword.TabIndex = 20
        '
        'txtUserName
        '
        Me.txtUserName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtUserName.Location = New System.Drawing.Point(92, 28)
        Me.txtUserName.Name = "txtUserName"
        Me.txtUserName.Size = New System.Drawing.Size(154, 20)
        Me.txtUserName.TabIndex = 19
        Me.txtUserName.Text = "sa"
        '
        'lblUserName
        '
        Me.lblUserName.Location = New System.Drawing.Point(4, 32)
        Me.lblUserName.Name = "lblUserName"
        Me.lblUserName.Size = New System.Drawing.Size(84, 16)
        Me.lblUserName.TabIndex = 18
        Me.lblUserName.Text = "User Name:"
        '
        'txtSrvName
        '
        Me.txtSrvName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtSrvName.Location = New System.Drawing.Point(92, 4)
        Me.txtSrvName.Name = "txtSrvName"
        Me.txtSrvName.Size = New System.Drawing.Size(154, 20)
        Me.txtSrvName.TabIndex = 15
        Me.txtSrvName.Text = "(local)"
        '
        'lblSrvName
        '
        Me.lblSrvName.Location = New System.Drawing.Point(4, 8)
        Me.lblSrvName.Name = "lblSrvName"
        Me.lblSrvName.Size = New System.Drawing.Size(84, 16)
        Me.lblSrvName.TabIndex = 14
        Me.lblSrvName.Text = "Server Name:"
        '
        'btnGetPkgList
        '
        Me.btnGetPkgList.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnGetPkgList.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnGetPkgList.Location = New System.Drawing.Point(378, 4)
        Me.btnGetPkgList.Name = "btnGetPkgList"
        Me.btnGetPkgList.Size = New System.Drawing.Size(142, 68)
        Me.btnGetPkgList.TabIndex = 22
        Me.btnGetPkgList.Text = "&Get DTS Package List"
        '
        'chklbPkgList
        '
        Me.chklbPkgList.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.chklbPkgList.CheckOnClick = True
        Me.chklbPkgList.Location = New System.Drawing.Point(4, 76)
        Me.chklbPkgList.Name = "chklbPkgList"
        Me.chklbPkgList.Size = New System.Drawing.Size(516, 334)
        Me.chklbPkgList.TabIndex = 23
        Me.chklbPkgList.ThreeDCheckBoxes = True
        '
        'lblFilePath
        '
        Me.lblFilePath.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblFilePath.Location = New System.Drawing.Point(4, 420)
        Me.lblFilePath.Name = "lblFilePath"
        Me.lblFilePath.Size = New System.Drawing.Size(100, 16)
        Me.lblFilePath.TabIndex = 24
        Me.lblFilePath.Text = "Output File Path:"
        '
        'txtOutFilePath
        '
        Me.txtOutFilePath.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtOutFilePath.Location = New System.Drawing.Point(108, 416)
        Me.txtOutFilePath.Name = "txtOutFilePath"
        Me.txtOutFilePath.Size = New System.Drawing.Size(412, 20)
        Me.txtOutFilePath.TabIndex = 25
        '
        'btnPkgSelected
        '
        Me.btnPkgSelected.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnPkgSelected.Enabled = False
        Me.btnPkgSelected.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnPkgSelected.Location = New System.Drawing.Point(96, 464)
        Me.btnPkgSelected.Name = "btnPkgSelected"
        Me.btnPkgSelected.Size = New System.Drawing.Size(424, 60)
        Me.btnPkgSelected.TabIndex = 26
        Me.btnPkgSelected.Text = "&Package Selected DTS Jobs"
        '
        'btnExit
        '
        Me.btnExit.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnExit.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnExit.Location = New System.Drawing.Point(4, 464)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(88, 60)
        Me.btnExit.TabIndex = 27
        Me.btnExit.Text = "E&xit"
        '
        'txtManifestFileName
        '
        Me.txtManifestFileName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtManifestFileName.Location = New System.Drawing.Point(252, 440)
        Me.txtManifestFileName.Name = "txtManifestFileName"
        Me.txtManifestFileName.Size = New System.Drawing.Size(268, 20)
        Me.txtManifestFileName.TabIndex = 28
        Me.txtManifestFileName.Text = "DTSManifest.xml"
        '
        'Label1
        '
        Me.Label1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Label1.Location = New System.Drawing.Point(136, 444)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(108, 16)
        Me.Label1.TabIndex = 29
        Me.Label1.Text = "Manifest File Name:"
        '
        'cbCrManifest
        '
        Me.cbCrManifest.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.cbCrManifest.Checked = True
        Me.cbCrManifest.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cbCrManifest.Location = New System.Drawing.Point(4, 444)
        Me.cbCrManifest.Name = "cbCrManifest"
        Me.cbCrManifest.Size = New System.Drawing.Size(128, 16)
        Me.cbCrManifest.TabIndex = 30
        Me.cbCrManifest.Text = "Create Manifest File"
        '
        'lbMessage
        '
        Me.lbMessage.Location = New System.Drawing.Point(4, 76)
        Me.lbMessage.Name = "lbMessage"
        Me.lbMessage.Size = New System.Drawing.Size(516, 329)
        Me.lbMessage.TabIndex = 31
        Me.lbMessage.Visible = False
        '
        'chkTrusted
        '
        Me.chkTrusted.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.chkTrusted.Checked = True
        Me.chkTrusted.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkTrusted.Location = New System.Drawing.Point(252, 6)
        Me.chkTrusted.Name = "chkTrusted"
        Me.chkTrusted.Size = New System.Drawing.Size(124, 16)
        Me.chkTrusted.TabIndex = 32
        Me.chkTrusted.Text = "Trusted Connection"
        '
        'chkSelectAllOnGet
        '
        Me.chkSelectAllOnGet.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.chkSelectAllOnGet.AutoSize = True
        Me.chkSelectAllOnGet.Checked = True
        Me.chkSelectAllOnGet.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkSelectAllOnGet.Location = New System.Drawing.Point(252, 54)
        Me.chkSelectAllOnGet.Name = "chkSelectAllOnGet"
        Me.chkSelectAllOnGet.Size = New System.Drawing.Size(105, 17)
        Me.chkSelectAllOnGet.TabIndex = 33
        Me.chkSelectAllOnGet.Text = "Select All on Get"
        Me.chkSelectAllOnGet.UseVisualStyleBackColor = True
        '
        'DTSPackager
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(524, 526)
        Me.Controls.Add(Me.chkSelectAllOnGet)
        Me.Controls.Add(Me.chkTrusted)
        Me.Controls.Add(Me.cbCrManifest)
        Me.Controls.Add(Me.txtManifestFileName)
        Me.Controls.Add(Me.txtOutFilePath)
        Me.Controls.Add(Me.txtPassword)
        Me.Controls.Add(Me.txtUserName)
        Me.Controls.Add(Me.txtSrvName)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnPkgSelected)
        Me.Controls.Add(Me.lblFilePath)
        Me.Controls.Add(Me.chklbPkgList)
        Me.Controls.Add(Me.btnGetPkgList)
        Me.Controls.Add(Me.lblPassword)
        Me.Controls.Add(Me.lblUserName)
        Me.Controls.Add(Me.lblSrvName)
        Me.Controls.Add(Me.lbMessage)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MinimumSize = New System.Drawing.Size(500, 350)
        Me.Name = "DTSPackager"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "DTS Packager"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub btnGetPkgList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetPkgList.Click
        Try
            Dim _oDataSet As DataSet
            Dim _oDataRow As DataRow
            Dim _sDTSJobName As String
            Dim _sSrvName As String

            'Flip the panels
            chklbPkgList.Visible = False
            lbMessage.Visible = True

            'Relinquish control back to OS
            System.Windows.Forms.Application.DoEvents()

            _sSrvName = TestConnection()

            If _sSrvName Is Nothing Then
                lbMessage.Items.Add("Connection Test Failed, please supply valid server name and credentials")
                lbMessage.Items.Add("Test of Database connection failed, aborting deployment.")
                lbMessage.Items.Add("Message returned: " & __sMessage)
                __bConnTested = False
                __sMessage = ""
                Return
            Else
                'lbMessage.Items.Add("Connected to server: " & _sSrvName)
                lbMessage.Items.Add("Connected to server: " & _sSrvName & " (" & String.Format(Now(), "MM/dd/yyyy hh:mm:ss") & ")")

                __bConnTested = True
                __sMessage = ""
            End If

            chklbPkgList.Items.Clear()

            _oDataSet = __oSQL.ExecuteDataSet(CommandType.Text, "SELECT DISTINCT DTSJobName = name FROM dbo.sysdtspackages")

            If _oDataSet.Tables(0).Rows.Count = 0 Then
                MsgBox("No packages were available on the specified server.", MsgBoxStyle.OkOnly, "Warning")

                btnPkgSelected.Enabled = False
            Else
                For Each _oDataRow In _oDataSet.Tables(0).Rows
                    _sDTSJobName = _oDataRow.Item("DTSJobName")

                    chklbPkgList.Items.Add(_sDTSJobName, chkSelectAllOnGet.Checked)
                    lbMessage.Items.Add("Adding DTS Job: [" & _sDTSJobName & "] to List")

                    'Relinquish control back to OS
                    System.Windows.Forms.Application.DoEvents()

                    btnPkgSelected.Enabled = True
                Next

                'Flip the panels
                chklbPkgList.Visible = True
                lbMessage.Visible = False
            End If
        Catch ex As Exception
            MsgBox("Exception Raised: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
        Finally
        End Try
    End Sub

    Private Sub btnPkgSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPkgSelected.Click
        Try
            Dim _oDataSet As DataSet
            Dim _oDataRow As DataRow
            Dim _iListIdx As Integer
            Dim _sDTSJobName As String
            Dim _sDTSJobNameCond As String
            Dim _sSQLCmd As String
            Dim _sDTSPackageData As Byte()
            Dim _sDTSFileNameWPath As String
            Dim _sManifestFileNameWPath As String = ""
            Dim _sSrvName As String
            Dim _fCrManifest As Boolean

            lbMessage.Visible = True
            chklbPkgList.Visible = False
            lbMessage.Items.Clear()

            If __bConnTested = False Then
                _sSrvName = TestConnection()

                If _sSrvName Is Nothing Then
                    lbMessage.Items.Add("Connection Test Failed, please supply valid server name and credentials")
                    lbMessage.Items.Add("Test of Database connection failed, aborting deployment.")
                    lbMessage.Items.Add("Message returned: " & __sMessage)
                    __bConnTested = False
                    __sMessage = ""
                    Return
                Else
                    lbMessage.Items.Add("Connected to server: " & _sSrvName & " (" & String.Format(Now(), "MM/dd/yyyy hh:mm:ss") & ")")

                    __bConnTested = True
                    __sMessage = ""
                End If
            End If

            _fCrManifest = cbCrManifest.Checked

            If _fCrManifest = True Then
                _sManifestFileNameWPath = CondFilePath(txtOutFilePath.Text) _
                                        & txtManifestFileName.Text.Trim

                WriteManifestFile(_sManifestFileNameWPath, "<DTSDeployList>", False)
            End If

            For _iListIdx = 0 To chklbPkgList.CheckedItems.Count - 1
                _sDTSJobName = chklbPkgList.CheckedItems.Item(_iListIdx).ToString.Trim
                _sDTSJobNameCond = CondFileName(_sDTSJobName.Trim)

                If _sDTSJobName <> _sDTSJobNameCond Then
                    lbMessage.Items.Add("Packaging: [" & _sDTSJobName & "] as [" & _sDTSJobNameCond & "]")
                Else
                    lbMessage.Items.Add("Packaging: [" & _sDTSJobName & "]")
                End If

                _sSQLCmd = "SELECT packagedata FROM dbo.sysdtspackages WHERE name = '" _
                         & _sDTSJobName _
                         & "' AND createdate = ( SELECT MAX( createdate ) FROM dbo.sysdtspackages WHERE name = '" _
                         & _sDTSJobName _
                         & "' )"

                _oDataSet = __oSQL.ExecuteDataSet(CommandType.Text, _sSQLCmd)

                _oDataRow = _oDataSet.Tables(0).Rows(0)

                _sDTSPackageData = _oDataRow.Item("packagedata")

                _sDTSFileNameWPath = CondFilePath(txtOutFilePath.Text) _
                                  & _sDTSJobNameCond _
                                  & ".dts"

                WriteDTSFile(_sDTSFileNameWPath, _sDTSPackageData)

                If _fCrManifest = True Then
                    WriteManifestFile(_sManifestFileNameWPath, "     <DTSJob>" & _sDTSJobNameCond & ".dts</DTSJob>", True)
                End If

                'Relinquish control back to OS
                System.Windows.Forms.Application.DoEvents()
            Next

            If _fCrManifest = True Then
                WriteManifestFile(_sManifestFileNameWPath, "</DTSDeployList>", True)
            End If

            chklbPkgList.Items.Clear()

            lbMessage.Items.Add("")
            lbMessage.Items.Add("Click Get List to package additional items")
        Catch ex As Exception
            MsgBox("Exception Raised: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
        End Try
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End
    End Sub

    Private Sub txtSrvName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSrvName.TextChanged
        __bConnTested = False
    End Sub

    Private Sub txtUserName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUserName.TextChanged
        __bConnTested = False
    End Sub

    Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged
        __bConnTested = False
    End Sub

    Private Sub chkTrusted_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTrusted.CheckStateChanged
        If chkTrusted.CheckState = CheckState.Checked Then
            txtUserName.Enabled = False
            txtPassword.Enabled = False
        ElseIf chkTrusted.CheckState = CheckState.Unchecked Then
            txtUserName.Enabled = True
            txtPassword.Enabled = True
        ElseIf chkTrusted.CheckState = CheckState.Indeterminate Then
            chkTrusted.CheckState = CheckState.Unchecked
        End If
    End Sub

    Private Function BuildConnectionString() As String
        Dim _sConnString As String

        If chkTrusted.Checked = False Then
            _sConnString = "Password=" & txtPassword.Text.Trim _
                         & ";Persist Security Info=True;" _
                         & "User ID=" & txtUserName.Text.Trim _
                         & ";Initial Catalog=msdb;" _
                         & "Data Source=" & txtSrvName.Text.Trim
        Else
            _sConnString = "Integrated Security=SSPI" _
                         & ";Persist Security Info=True;" _
                         & ";Initial Catalog=msdb;" _
                         & "Data Source=" & txtSrvName.Text.Trim
        End If

        Return _sConnString
    End Function

    Private Function TestConnection() As String
        Try
            Dim _oDataSet As DataSet
            Dim _oDataRow As DataRow
            Dim _sSQLCmd As String

            __oSQL = New Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase(BuildConnectionString)

            'Build Command
            _sSQLCmd = "SELECT SrvName = @@SERVERNAME"

            'Get Data Set 
            _oDataSet = __oSQL.ExecuteDataSet(CommandType.Text, _sSQLCmd)

            If _oDataSet Is Nothing Then
                Return Nothing
            Else
                _oDataRow = _oDataSet.Tables(0).Rows(0)
                Return Trim(_oDataRow.Item("SrvName"))
            End If
        Catch ex As Exception
            'MsgBox("Exception Raised in TestConnection: " & ex.ToString, MsgBoxStyle.OKOnly, "Exception Raised")
            __sMessage = ex.Message.Trim
            Return Nothing
        End Try
    End Function

    Private Function ByteArrayToStringArray(ByRef BinaryData As Byte()) As String()
        Dim bByte As Byte
        Dim iCnt As Integer = 1
        Dim sWk(BinaryData.Length) As String

        sWk(0) = "0x"

        For Each bByte In BinaryData
            sWk(iCnt) = Microsoft.VisualBasic.Right("000" & Hex(bByte), 2)
            iCnt = iCnt + 1
        Next

        Return sWk
    End Function

    Private Function ByteArrayToHex(ByRef BinaryData As Byte()) As String
        Dim _sWk As String = ""

        Try
            _sWk = String.Join("", ByteArrayToStringArray(BinaryData))
        Catch ex As Exception
            MsgBox("Exception Raised: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
        End Try

        Return _sWk
    End Function

    Private Function CondFilePath(ByVal FilePath As String) As String
        FilePath = FilePath.Trim

        If FilePath.Substring(0, 1) = "\" Then
            Return FilePath
        Else
            Return FilePath & "\"
        End If
    End Function

    Private Function CondFileName(ByVal FileName As String) As String
        FileName = FileName.Trim
        FileName = FileName.Replace("\", "_0_")
        FileName = FileName.Replace(":", "_1_")
        FileName = FileName.Replace("|", "_2_")
        FileName = FileName.Replace("*", "_3_")
        FileName = FileName.Replace("+", "_4_")
        FileName = FileName.Replace(Chr(34), "_9_")

        Return FileName
    End Function

    Private Function WriteManifestFile(ByVal FileNameWPath As String, ByVal FileData As String, ByVal AppendFlag As Boolean) As Boolean
        Try
            Dim _oFIO As New IO.StreamWriter(FileNameWPath, AppendFlag)
            _oFIO.Write(FileData & vbCrLf)
            _oFIO.Close()
            Return True
        Catch ex As Exception
            MsgBox("Exception Raised: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
            Return False
        End Try
    End Function

    Private Function WriteDTSFile(ByVal FileNameWPath As String, ByVal FileBytes() As Byte) As Boolean
        Try
            Dim _dDt As Date = Now()

            Dim _oFIO As New IO.FileStream(FileNameWPath, IO.FileMode.Create)
            _oFIO.Write(FileBytes, 0, FileBytes.Length)
            _oFIO.Close()

            Dim _oFI As New System.IO.FileInfo(FileNameWPath)
            _oFI.CreationTime = _dDt
            _oFI.LastWriteTime = _dDt
            _oFI.LastAccessTime = _dDt

            Return True
        Catch ex As Exception
            MsgBox("Exception Raised: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
            Return False
        End Try
    End Function
End Class
